package com.jcl.recruit.log.logic;

import com.jcl.core.utils.CollectionUtils;
import com.jcl.recruit.log.mapper.ResumeLogMapper;
import com.jcl.recruit.log.model.ResumeLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.*;

/**
 * @ClassName ResumeLogLogic
 * @Description TODO
 * @Author yyliu
 * @Date 2018/10/31 16:30
 * @Version 1.0
 **/
@Component
public class ResumeLogLogic implements ResumeLogMapper {

    @Autowired
    private ResumeLogMapper resumeLogMapper;

    public List<Integer> findResumeIds(String corpCode, Integer userId, Integer category) {
        List<ResumeLog> list = resumeLogMapper.findListByCorp(corpCode, userId, category);
        List<Integer> resumeIds = new ArrayList<>();
        if(CollectionUtils.isNotEmpty(list)){
            for(ResumeLog entity: list){
                resumeIds.add(entity.getResumeId());
            }
        }

        return resumeIds;
    }

    public Map<Integer, Integer> findCountResumeMapByUsers(List<Integer> userIds, Integer category) {
        Map<Integer, Integer> dataMap = new HashMap<>();
        List<Map<String, Object>> list = resumeLogMapper.findCountResumeByUsers(userIds, category);
        if(CollectionUtils.isNotEmpty(list)){
            for(Map<String, Object> map: list){
                Integer userId = Integer.valueOf(map.get("userId").toString());
                Integer number = Integer.valueOf(map.get("number").toString());
                dataMap.put(userId, number);
            }
        }
        return dataMap;
    }


    public ResumeLog addResumeLog(String corpCode,
                                  Integer userId,
                                  Integer resumeId,
                                  String content,
                                  Integer category,
                                  String resumeType){

        ResumeLog log = new ResumeLog();
        log.setLog(content);
        log.setCategory(category);
        log.setResumeType(resumeType);
        log.setUserId(userId);
        log.setResumeId(resumeId);
        log.setCorpCode(corpCode);
        log.setCreatetime(new Date());
        resumeLogMapper.insert(log);
        return log;
    }

    @Override
    public List<ResumeLog> findList(Integer resumeId) {
        return resumeLogMapper.findList(resumeId);
    }

    @Override
    public List<ResumeLog> findListByCorp(String corpCode, Integer userId, Integer category) {
        return resumeLogMapper.findListByCorp(corpCode, userId, category);
    }

    @Override
    public List<Map<String, Object>> selectResumeLogsByResumeId(Integer resumeId) {
        return resumeLogMapper.selectResumeLogsByResumeId(resumeId);
    }

    @Override
    public List<Map<String, Object>> findCountResumeByUsers(List<Integer> userIds, Integer category) {
        return resumeLogMapper.findCountResumeByUsers(userIds, category);
    }

    @Override
    public int insert(ResumeLog record) {
        return resumeLogMapper.insert(record);
    }
}
